	real(8) function deff(w1,w1f,w1cf,w1csf,char3f,dt,de,epsilon,GradChar)
	use Data_cfoam, only: epsMaximumPrinciple
	implicit none
!	    real *8 deff
	    real *8 w1,w1f,w1cf,w1csf,char3f,dt,de,w1n
	    real *8 w1well,w1maxf,w1minf,w1cfold
	    real *8 epsilon
	    real(8),intent(in),optional :: GradChar
    !	include 'epsilon.h'
        if(present(GradChar))then
	        w1well=(w1csf-w1cf)/(0.5d0*dt)+char3f*GradChar ! (w1f-w1)/de
	    else
	        w1well=(w1csf-w1cf)/(0.5d0*dt)+char3f*(w1f-w1)/de
	    end if
	    w1maxf=dmax1(w1,w1cf,w1f)+dt*w1well + epsMaximumPrinciple
	    w1minf=dmin1(w1,w1cf,w1f)+dt*w1well - epsMaximumPrinciple
    !	w1n=2*w1csf-w1f
	    w1n=(2*w1csf-w1f*(1.0d0-epsilon))/(1.0d0+epsilon)

	    if(w1n.gt.w1maxf) w1n=w1maxf
	    if(w1n.lt.w1minf) w1n=w1minf
	    deff=w1n
	    return
	end function deff
	    